package com.aloda.service.impl;

import com.aloda.dto.MerPageDTO;
import com.aloda.mapper.MerchandiseMapper;
import com.aloda.result.PageResult;
import com.aloda.service.MerchandiseService;
import com.aloda.vo.MerPageVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MerchandiseServiceImpl implements MerchandiseService {

    @Autowired
    private MerchandiseMapper merchandiseMapper;

    /**
     * 商品分页查询
     *
     * @param merPageDTO
     * @return
     */
    @Override
    public PageResult pageQuery(MerPageDTO merPageDTO) {
        if(merPageDTO.getBegin()!=null&&merPageDTO.getEnd()!=null){
            merPageDTO.setBegin(merPageDTO.getBegin().plusHours(8));
            merPageDTO.setEnd(merPageDTO.getEnd().plusHours(8));
        }
        PageHelper.startPage(merPageDTO.getPage(), merPageDTO.getPageSize());
        Page<MerPageVO> page = merchandiseMapper.pageQuery(merPageDTO);
        PageResult pageResult = new PageResult(page.getTotal(),page.getResult());
        return pageResult;
    }
}
